package com.pms.actions;

import java.util.Hashtable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pms.businesslogic.BusinessDelegator;
import com.pms.businesslogic.LogicFactory;
import com.pms.framework.Action;
import com.pms.framework.JSPUtility;
import com.pms.platform.dto.User;
import com.pms.utils.Converter;
import com.pms.utils.ValueObject;

public class FillComboAction implements Action{
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		
		try{

			ValueObject inValObj=Converter.convertToValueObject(request);
			if(request.getSession().getAttribute("user")==null){
				Hashtable errHash=new Hashtable();
				errHash.put("error", "Your session has been expired. ");
				request.setAttribute("errHash", errHash);
				request.setAttribute("nextPageToken", "needLogin");
				return;
			}
			
			User user=(User)request.getSession().getAttribute("user");
			boolean isSuperAdmin=false;
			if(request.getSession().getAttribute("isSuperAdmin")!=null){
				isSuperAdmin=Boolean.parseBoolean(request.getSession().getAttribute("isSuperAdmin").toString());
			}
			inValObj.put("user", user);
			inValObj.put("isSuperAdmin", isSuperAdmin);
			int actionEvent =JSPUtility.GetInt(request,"actionEvent");
			int numOfJobs =JSPUtility.GetInt(request,"numOfJobs",1);
			int numOfMiscJobs=JSPUtility.GetInt(request,"numOfMiscJobs",1);
			BusinessDelegator blObj= LogicFactory.getInstance().getBusinessLogic(actionEvent);
			
			ValueObject resValObj =blObj.getComboData(inValObj);
			
			
			resValObj.transferToRequest(request);
			
			long milliSec= System.currentTimeMillis();
			request.setAttribute("prevRequestTracker", milliSec);
			
			//Category[] category = CategoryDao.getInstance().findAll();
			//PrintSizeMaster[] prinSizes = PrintSizeMasterDao.getInstance().findAll();
			
			//request.setAttribute("printSizes", prinSizes);
			//request.setAttribute("category", category);
			request.setAttribute("numOfMiscJobs", numOfMiscJobs);
			request.setAttribute("numOfJobs", numOfJobs);
			System.out.println("@@@@@ numOfJobs == "+numOfJobs+" numOfMiscJobs "+numOfMiscJobs);
			request.setAttribute("actionEvent", actionEvent);
			request.setAttribute("nextPageToken", "success");
			

			String prevSelMenu = JSPUtility.GetString(request, "PrevSelMenu","");
			request.setAttribute("PrevSelMenu", prevSelMenu);
			System.out.println("@@@@@@@ prevSelMenu ===> "+prevSelMenu);
			
			
		}catch (Exception e) {
			e.printStackTrace();
		}

	}

}

